package stackdemo;

import java.util.Stack;

public class Test {

    //最小栈
    public static void main(String[] args) {

    }


    //判断栈的压入、弹出序列是否匹配
    public static boolean IsPopOrder(int[] pushV, int[] popV) {
        Stack<Integer> stack = new Stack<>();

        int j = 0;
        for (int i = 0; i < pushV.length; i++) {
            stack.push(pushV[i]);

            while (j < popV.length && !stack.empty() && stack.peek() == popV[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }

    public static void main1(String[] args) {
        int[] pushV = {1, 2, 3, 4, 5};
        int[] popV = {4, 5, 3, 2, 1};
        System.out.println(IsPopOrder(pushV, popV));
    }
}
